﻿
using System;
using System.Timers;

class AlarmClock
{
    public delegate void TickEventHandler(object sender, EventArgs e);
    public delegate void AlarmEventHandler(object sender, EventArgs e);

    public event TickEventHandler Tick;
    public event AlarmEventHandler Alarm;

    private Timer timer;
    private int seconds;

    public AlarmClock(int seconds)
    {
        this.seconds = seconds;
        timer = new Timer(1000);
        timer.Elapsed += TimerElapsed;
    }

    public void Start()
    {
        timer.Start();
    }

    private void TimerElapsed(object sender, ElapsedEventArgs e)
    {
   
        OnTick();

        seconds--;
        if (seconds <= 0)
        {
            timer.Stop();
            OnAlarm();
        }
    }

    protected virtual void OnTick()
    {
        Tick?.Invoke(this, EventArgs.Empty);
    }

    protected virtual void OnAlarm()
    {
        Alarm?.Invoke(this, EventArgs.Empty);
    }
}

class Program
{
    static void Main()
    {
        AlarmClock alarm = new AlarmClock(5);

        alarm.Tick += (sender, e) => Console.WriteLine("Tick...");
        alarm.Alarm += (sender, e) => Console.WriteLine("时间到！");

        alarm.Start();

        Console.WriteLine("闹钟已启动");
        Console.ReadLine();
    }
}